<?php

class rute{
	
	// Class Constructor
	public function __construct(){
		$this->db = new DBClass();
	}
	
	public function getRute(){
		
		$query = "Select * from rute";
		$rows = $this->db->getRows($query);
		
		return $rows;
	}

	public function get_data(){
		$query = "select idadmin, username, fullname, email from admin 
			where username='".$_COOKIE['c_usr']."'";

		$rows = $this->db->getRows($query);

		return $rows[0];	
	}
	public function hapusRute($data){
		
		$query ="DELETE FROM rute WHERE kode_rute='".@$data."'";

		$rows = $this->db->getRows($query);

		header('Location: rute.php');
	}

	public function editRute($data){
		
		$query ="SELECT * FROM rute WHERE kode_rute='".@$data."'";
		$rows = $this->db->getRows($query);

		return array_shift($rows);
		}
	public function Tambahrute($data){
		
		$query ="INSERT INTO `rute` (`kode_rute`, `dari`, `ke`) VALUES ('".@$data[0]."', '".@$data[1]."', '".@$data[2]."')";

		$this->db->putRows($query);

		header('Location: rute.php');
	}

public function PostEdit($data){
		
		$query ="UPDATE rute SET dari='".$data[1]."', ke='".$data[2]."' WHERE kode_rute='".$data[0]."'";

		$this->db->putRows($query);
	}
}